# -*- coding: utf-8 -*-
# Generated by Django 1.11 on 2017-09-15 04:30
from __future__ import unicode_literals

from django.db import migrations, models, transaction
import json

def migrate(apps, schema_editor):
    Chart = apps.get_model('grapher_admin', 'Chart')
    with transaction.atomic():
        for chart in Chart.objects.all():
            config = json.loads(chart.config)

            if 'label' in config['yAxis']:
                if chart.type == "ScatterPlot":
                    for dim in chart.chartdimension_set.all():
                        if dim.property == 'y' and not dim.displayName:
                            dim.displayName = config['yAxis']['label']
                            dim.save()
                del config['yAxis']['label']
            
            if 'label' in config['xAxis']:
                if chart.type == "ScatterPlot":
                    for dim in chart.chartdimension_set.all():
                        if dim.property == 'x' and not dim.displayName:
                            dim.displayName = config['xAxis']['label']
                            dim.save()
                del config['xAxis']['label']

            
            chart.config = json.dumps(config)
            chart.save()

class Migration(migrations.Migration):

    dependencies = [
        ('grapher_admin', '0015_auto_20170914_1138'),
    ]

    operations = [
        migrations.RunPython(migrate)
    ]

# -*- coding: utf-8 -*-
# Generated by Django 1.11 on 2017-09-15 04:30
from __future__ import unicode_literals

from django.db import migrations, models, transaction
import json

def migrate(apps, schema_editor):
    Chart = apps.get_model('grapher_admin', 'Chart')
    with transaction.atomic():
        for chart in Chart.objects.all():
            config = json.loads(chart.config)

            if 'label' in config['yAxis']:
                if chart.type == "ScatterPlot":
                    for dim in chart.chartdimension_set.all():
                        if dim.property == 'y' and not dim.displayName:
                            dim.displayName = config['yAxis']['label']
                            dim.save()
                del config['yAxis']['label']
            
            if 'label' in config['xAxis']:
                if chart.type == "ScatterPlot":
                    for dim in chart.chartdimension_set.all():
                        if dim.property == 'x' and not dim.displayName:
                            dim.displayName = config['xAxis']['label']
                            dim.save()
                del config['xAxis']['label']

            
            chart.config = json.dumps(config)
            chart.save()

class Migration(migrations.Migration):

    dependencies = [
        ('grapher_admin', '0015_auto_20170914_1138'),
    ]

    operations = [
        migrations.RunPython(migrate)
    ]

# -*- coding: utf-8 -*- # Generated by Django 1.11 on 2017-09-15 04:30